<?php
/*
 * 订单导入导出数据处理类
 * */
class importexport_data_b2c_orders {


    /**
     * 导出订单数据，修改数据库已有数据
     *
     * @params array $row 数据库中一条订单数据
     * @return array $row 修改过后的数据
     */
    public function get_content_row($row){
//        if(intval($row['member_id'])){
//            $member_name = app::get('members')->getRow("*",array('member_id'=>$row['member_id']));
//            if($member_name['name']){
//                $login_name = $member_name['name'];
//            }else{
//                $login_name = app::get('pam')->model('members')->get_operactor_name($row['member_id']);
//            }
//        }else{
//            $login_name = $row['member_id'];
//        }
//        $row['member_id'] = $login_name;
        
        if($row['payment'] == '-1'){
            $row['payment'] = app::get('importexport')->_('货到付款');
        }
        $data[0] = $row;
        return $data;
    }//end function
    
    
    /**
     * 获取商品明细：商品明细（商品货号、商品名称、商品属于哪个供应商、商品单价、商品购买数量）。
     */
    public function get_goods_row($order_id){
        $db = kernel::database();

        $sql = "SELECT boi.name,bg.bn,FORMAT(boi.price,2) AS `price`,boi.nums,FORMAT(boi.amount,2) AS `amount` FROM `sdb_b2c_order_items` boi
                                INNER JOIN `sdb_b2c_goods` bg ON bg.goods_id = boi.goods_id 
                                 WHERE boi.order_id='$order_id'";
        //logger::info("sql：".var_export($sql,1));
        $datas = $db->select($sql);
        foreach ($datas as $k=>$data){
            $sql = "select payment_id from sdb_ectools_payments where payment_id like '%".$order_id."%'";
            $data_p = $db->select($sql);
            $datas[$k]['payment_id'] = $data_p[0]['payment_id'];
        }
        return $datas;
    }//end function
    
    /*
     * 获取导出字段
     */
    public function get_title( $title = array() ){
        $title = array (
            'order_id' => '订单号(order_id)',
            'member_id' => '会员用户名(member_id)',
            'createtime' => '下单时间(createtime)',
            'pay_status' => '付款状态(pay_status)',
            'shipping_id' => '配送方式(shipping_id)',
            'cardnum' => '身份证号(cardnum)',
           
            'name' => '商品名称',
            'bn' => '商品货号',
//            'supplier' => '供应商',
            'price' => '商品单价',
            'nums' => '商品购买数量',
            'amount' => '商品总价',
            'payment_id' => '支付交易号',
            'final_amount' => '订单总额(final_amount)',           
            'cost_freight' => '配送费用(cost_freight)',
            'mark_text' => '订单备注(mark_text)',
            'tax_content' => '发票内容(tax_content)',
            'ship_time' => '(ship_time)',
            'ship_name' => '收货人(ship_name)',
            'ship_mobile' => '收货人手机(ship_mobile)',
            'ship_tel' => '收货人电话(ship_tel)',            
            'ship_addr' => '收货地址(ship_addr)',
            
            'total_amount' => '(total_amount)',
            'mark_type' => '订单备注图标(mark_type)',
            'ship_status' => '发货状态(ship_status)',
            'is_delivery' => '(is_delivery)',
           
            'last_modified' => '最后更新时间(last_modified)',
            'payment' => '支付方式(payment)',
            'shipping' => '配送方式(shipping)', 

           
            'status' => '订单状态(status)',
            'confirm' => '确认状态(confirm)',
            'ship_area' => '收货地区(ship_area)',
           
            'weight' => '(weight)',
            'tostr' => '(tostr)',
            'itemnum' => '(itemnum)',
            'ip' => 'IP地址(ip)',

            'ship_zip' => '(ship_zip)',

            'ship_email' => '(ship_email)',


            'cost_item' => '(cost_item)',
            'is_tax' => '(is_tax)',
            'tax_type' => '(tax_type)',

            'cost_tax' => '(cost_tax)',
            'tax_company' => '(tax_company)',
            'is_protect' => '(is_protect)',
            'cost_protect' => '(cost_protect)',
            'cost_payment' => '(cost_payment)',
            'currency' => '(currency)',
            'cur_rate' => '(cur_rate)',
            'score_u' => '(score_u)',
            'score_g' => '(score_g)',
            'discount' => '(discount)',
            'pmt_goods' => '(pmt_goods)',
            'pmt_order' => '(pmt_order)',
            'payed' => '(payed)',
            'memo' => '(memo)',
            'disabled' => '(disabled)',



            'extend' => '(extend)',
            'order_refer' => '(order_refer)',
            'addon' => '(addon)',
            'source' => '平台来源(source)',
          );

        return $this->title = $title;
    }
}
